//
//  HRChatMessageToolBar.m
//  Hear
//
//  Created by mac on 2017/10/19.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HRChatMessageToolBar.h"
#import "NYWaterWaveView.h"
#import "HRRecordButton.h"

@interface HRChatMessageToolBar ()
@property(nonatomic, strong) NYWaterWaveView *waterWaveView;
@property(nonatomic, strong)UIButton *bordButton;
@property(nonatomic, strong)UIButton *addButton;
@property(nonatomic, strong)HRRecordButton *recodButton;

@end
@implementation HRChatMessageToolBar

- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self setupConfigure];
        
    }
    return self;
}

- (void)setupConfigure{
    
    NYWaterWaveView *waterWaveView = [[NYWaterWaveView alloc]initWithFrame:CGRectMake(0, 20, self.width, 20)];
    [self addSubview:(self.waterWaveView=waterWaveView)];
    [waterWaveView stopAnimation];
    UIView *toolView = [UIView new];
    [self addSubview:toolView];
    toolView.frame = CGRectMake(0, waterWaveView.bottom, self.width, 50);
    
    CGFloat leftPading = 10;
    
    CGFloat topPading = 5;

    
    UIButton *bordButton = [UIButton buttonWithType:0];
    [bordButton addTarget:self action:@selector(bordButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [toolView addSubview:(self.bordButton=bordButton)];
    [bordButton setImage:[UIImage imageNamed:@"键盘"] forState:0];
    bordButton.frame = CGRectMake(leftPading, topPading, toolView.height-topPading*2, toolView.height-topPading*2);
    
    UIButton *addButton = [UIButton buttonWithType:0];
    [addButton addTarget:self action:@selector(bordButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [toolView addSubview:(self.addButton=addButton)];
    [addButton setImage:[UIImage imageNamed:@"IM_更多"] forState:0];
    addButton.frame = CGRectMake(toolView.width-leftPading-bordButton.width, bordButton.top, bordButton.width, bordButton.width);
    WeakSelf
    HRRecordButton *recodButton = [[HRRecordButton alloc] initWithFrame:CGRectMake((toolView.width-70)/2, 0, 70, 70)];
    [self addSubview:recodButton];
    recodButton.isSelctRecordBlock = ^(BOOL isSelect) {
        if (isSelect){
            weakSelf.waterWaveView.backImageView.hidden = YES;
            [weakSelf.waterWaveView startAnimation];
        }else{
            weakSelf.waterWaveView.backImageView.hidden = NO;
            [weakSelf.waterWaveView stopAnimation];
        }
    };
}
- (void)bordButtonClick:(UIButton *)button{
    button.selected =!button.isSelected;
    if (button.selected){
        [button setImage:[UIImage imageNamed:@"IM_语音"] forState:0];
    }else{
        [button setImage:[UIImage imageNamed:@"键盘"] forState:0];
    }
}

@end
